<?php
$loader->requireOnce('includes/LabConnector/ILabConnector.class.php');
$loader->requireOnce('includes/EnumerationConstant.class.php');
/**
 * Connector for lab module deal with inpatient.
 * @package include
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class InpatientLabConnector implements ILabConnector {

	private $logger ;
	function __construct() {
		$this->logger = LoggerManager::getLogger('includes.LabConnector.InpatientLabConnector');
	}
	/**
	 * Action be called after an assignment is deleted.
	 * @param $ticketId
	 * @param $labAssignmentTicketId
	 * @return unknown_type
	 */
	public function doAfterAssignmentDeleted($ticketId, $labAssignmentTicketId) {
		$this->logger->info("Start doAfterAssignmentDeleted[" . $ticketId . "," . $labAssignmentTicketId . "]");
		$itemType = Utils::getEnumKey(EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE, EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE_LAB);
		$inTicketItemObject = Celini::newOrdo("InTicketItem");
		$inTicketItemObject->deleteItem($labAssignmentTicketId, $itemType);
		$this->logger->info("Finish doAfterAssignmentDeleted[" . $ticketId . "," . $labAssignmentTicketId . "]");

	}
	/**
	 * Action be called after an assignment is created.
	 * @param $ticketId
	 * @param $labAssignmentTicketId
	 * @param $data   =   array('date','item_id',
	 'original_price','insurance_price','patient_price','ticket_id'
	 );
	 * @return key of created row
	 */
	public function doAfterAssignmentCreated($ticketId, $labAssignmentTicketId,  $data = array()) {
		$this->logger->info("Start doAfterAssignmentCreated[" . $ticketId . "," . $labAssignmentTicketId . "]");
		//create in_ticket_item
		$inTicketItemObject = Celini::newOrdo("InTicketItem");
		$itemType = Utils::getEnumKey(EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE, EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE_LAB);
		$inTicketItemObject->setData($data['item_id'], $itemType, 0,
		$data['original_price'], $data['insurance_price'], $data['patient_price'], $data['ticket_id'], $data['date']);
		$inTicketItemObject->persist();
		$this->logger->info("Finish doAfterAssignmentCreated[" . $ticketId . "," . $labAssignmentTicketId . "]");
		return $inTicketItemObject->get_id();
	}
	/**
	 * Action be called after an assignment is finished.
	 * @param $ticketId
	 * @param $labAssignmentTicketId
	 * @param $data   =   array('original_price', 'insurance_price', 'patient_price');
	 * @return unknown_type
	 */
	function doAfterAssignmentFinished($ticketId, $labAssignmentTicketId, $data = array()) {
		$this->logger->info("Start doAfterAssignmentFinished[" . $ticketId . "," . $labAssignmentTicketId . "]");
		//create in_ticket_item
		$inTicketItemObject = Celini::newOrdo("InTicketItem");
		$itemType = Utils::getEnumKey(EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE, EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE_LAB);
		$inTicketItemObject->updateData($labAssignmentTicketId, $itemType, $data);
		$this->logger->info("Finish doAfterAssignmentFinished[" . $ticketId . "," . $labAssignmentTicketId . "]");
		 
		 
	}

	public function doWhileAssignmentProcessing($ticketId, $labAssignmentTicketId) {

	}
	public function doAfterAssignmentCanceled($ticketId, $labAssignmentTicketId) {
			 
	}

	 

}
?>